<?php
/**
 * The control file of index module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
class setting extends control
{
    /**
     * The construct function.
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * The index page.
     * 
     * @access public
     * @return void
     */
    public function index()
    {

        $model = 'monitors';
        if($_POST){
        $unit = $this->setting->setunit($model);

            if(dao::isError())  $this->send(array('result' => 'fail', 'message' => dao::getError()));
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('setting', 'index')));
        }

        $unit = $this->setting->getunit($model);
        $this->view->title = $this->lang->setting->index;
        $this->view->unit  = $this->loadModel('process')->getdepartment();
        $this->view->setunit = $unit->unit_id;
        $this->view->personnel = $this->loadModel('process')->getuser();
        $this->view->setpersonnel = $unit->personnel;
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function setaudit()
    {
        $model = 'audit';
        if($_POST){
            $unit = $this->setting->setunit($model);
            if(dao::isError())  $this->send(array('result' => 'fail', 'message' => dao::getError()));
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('setting', 'setaudit')));
        }

        $unit = $this->setting->getunit($model);
        $this->view->title = $this->lang->setting->setaudit;
        $this->view->unit  = $this->loadModel('process')->getdepartment();
        $this->view->setunit = $unit->unit_id;
        $this->view->personnel = $this->loadModel('process')->getuser();
        $this->view->setpersonnel = $unit->personnel;
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function setadmin()
    {
        $model = 'admin';
        if($_POST){
            $unit = $this->setting->setunit($model);
            if(dao::isError())  $this->send(array('result' => 'fail', 'message' => dao::getError()));
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('setting', 'setadmin')));
        }

        $unit = $this->setting->getunit($model);
        $this->view->title = $this->lang->setting->setadmin;
        $this->view->unit  = $this->loadModel('process')->getdepartment();
        $this->view->setunit = $unit->unit_id;
        $this->view->personnel = $this->loadModel('process')->getuser();
        $this->view->setpersonnel = $unit->personnel;
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function setbanner(){
        if($_POST){
            $banner = $this->setting->setbanner();
            if(dao::isError())  $this->send(array('result' => 'fail', 'message' => dao::getError()));
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('setting', 'setbanner')));
        }

        $this->view->title = $this->lang->setting->setbanner;
        $this->view->banner = $this->setting->getbanner();
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }
    public function setvideo(){

        if($_POST){
            $video = $this->setting->setvideo();
            if(dao::isError())  $this->send(array('result' => 'fail', 'message' => dao::getError()));
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('setting', 'setvideo')));
        }

        $this->view->title = $this->lang->setting->setvideo;
        $this->view->video = $this->setting->getvideo();

        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }
    public function showvideo(){

        $this->view->video = $this->setting->getvideo();
        $this->display();
    }

    public function setlink(){

        if($_POST){
            $link = $this->setting->setlink();

            if(dao::isError())  $this->send(array('result' => 'fail', 'message' => dao::getError()));
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('setting', 'setlink')));
        }
        $this->view->title = $this->lang->setting->setlink;
        $this->view->links = $this->setting->getlink();
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }
    public function setcategory(){
        $bigcategory = $this->setting->getcatecoryall();

       $this->view->bigcategory = $bigcategory;
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function addbigcategory(){

        if($_POST){
            $queren = $this->setting->addbigcategory();
            $this->send(array('result' => 'success', 'message' => $queren, 'locate' => $this->createLink('setting', 'setcategory')));
        }

        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function addproject(){

        if($_POST){
            $queren = $this->setting->addproject();
            $this->send(array('result' => 'success', 'message' => $queren, 'locate' => $this->createLink('setting', 'setcategory')));
        }

        $bigcategory = $this->loadModel('process')->getbigtype();
        $this->view->bigcategory = $bigcategory;
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function ajaxproject($bid){

        $types = $this->setting->getproject($bid);
        $html  = '';
        foreach($types as $id => $type)
        {
            $html .= "<option value='{$id}'>$type</option>";
        }
        echo $html;
    }

    public function addcategory(){

        if($_POST){
            $queren = $this->setting->addcategory();
            $this->send(array('result' => 'success', 'message' => $queren, 'locate' => $this->createLink('setting', 'setcategory')));
        }
        $bigcategory = $this->loadModel('process')->getbigtype();
        $this->view->bigcategory = $bigcategory;
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function addcategorys($pid,$cpid){
        if($_POST){
            $queren = $this->setting->addcategorys($pid,$cpid);
            $this->send(array('result' => 'success', 'message' => $queren, 'locate' => $this->createLink('setting', 'setcategory')));
        }
        $this->view->pid = $pid;
        $this->view->cpid = $cpid;
        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function editcategory($id){
        if($_POST){
            $queren = $this->setting->editcategory($id);
            $this->send(array('result' => 'success', 'message' => $queren, 'locate' => $this->createLink('setting', 'setcategory')));
        }

        $category = $this->setting->getcategorybyid($id);
        $this->view->category = $category;

        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function editproject($id){
        if($_POST){
            $queren = $this->setting->editproject($id);
            $this->send(array('result' => 'success', 'message' => $queren, 'locate' => $this->createLink('setting', 'setcategory')));
        }

        $category = $this->setting->getprojectbyid($id);
        $this->view->category = $category;

        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function editbigcategory($id){
        if($_POST){
            $queren = $this->setting->editbigcategory($id);
            $this->send(array('result' => 'success', 'message' => $queren, 'locate' => $this->createLink('setting', 'setcategory')));
        }

        $category = $this->setting->getbigcategorybyid($id);
        $this->view->category = $category;

        $user = $_SESSION['user'];
        if($this->loadModel('process')->ismonitors('admin')||$user->police_number=='admin'){
            $this->display();
        }else{
            die(js::error('权限不够,请联系管理员') . js::locate('back'));
        }
    }

    public function delcategory(){

        $id = $this->post->id;
        $del = $this->setting->delcategory($id);

        echo $del;
        exit;

    }

    public function delproject(){
        $id = $this->post->id;
        $del = $this->setting->delproject($id);

        echo $del;
        exit;
    }

    public function delbigcategory(){
        $id = $this->post->id;
        $del = $this->setting->delbigcategory($id);

        echo $del;
        exit;
    }

}
